'use strict';

const Service = require('egg').Service;

class ClazzService extends Service {
    // resources  index / create / destroy / update

    // 查询
    async index() {
        try {
            let res = await this.app.model.Clazz.findAll({
                include: { model: this.app.model.Book },
            });
            return res
        } catch (err) { console.log(err) }
    }
    // 添加
    async create() {
        try {
            let clazz = this.ctx.request.body.clazz;
            await this.app.model.Clazz.create({
                category: clazz,
            });
            let res = await this.app.model.Clazz.findAll();
            return res
        } catch (err) { console.log(err) }
    }
}

module.exports = ClazzService;
